<?php

namespace App\Admin\Repositories;

use App\Models\PlazaModel as Model;
use Dcat\Admin\Form;
use Dcat\Admin\Repositories\EloquentRepository;

class Plaza extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;


    public function store(Form $form)
    {
        $type = $form->input('cur_type');
//        dd($form->input());
        if ($type == $this->eloquentClass::TYPE_JOB_POSITION) {
            $idArray = $form->input('job_position_id');
            $images = $form->input('images');
            $idArray = explode(',', $idArray);
            foreach ($idArray as $id) {
                $res = $this->eloquentClass::query()->updateOrCreate([
                    'cur_type' => $type,
                    'images' => $images,
                    'job_position_id' => $id
                ]);
            }
            return $res;
        } else {
            return parent::store($form); // TODO: Change the autogenerated stub

        }
    }
}
